package Socket.test.server_socket;

import Socket.test.DBUtils.User;
import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.Element;
import org.dom4j.Node;
import org.dom4j.io.SAXReader;
import org.junit.Test;

import java.io.File;
import java.lang.reflect.Method;

public class XmlUtils {

    public static String getClassName(String pattern){
        SAXReader reader = new SAXReader();
        Document doc =null;
        try {
            doc = reader.read("src/Socket/test/server_socket/configer.xml");
        } catch (DocumentException e) {
            e.printStackTrace();
        }
        Element root = doc.getRootElement();
        String url = "/user";
        String xpath = "  //servlet[servlet-name=//servlet-mapping[url-pattern='"+url+"']/servlet-name/text()]/servlet-class";
        Node node = root.selectSingleNode(xpath);
        String className = node.getText();
        return className;

    }

    @Test
    public void fun() throws Exception {

        Class clazz = Class.forName("Socket.test.DBUtils.Login");
        Object object = clazz.newInstance();
        Method method = clazz.getMethod("login", String.class, String.class);
       String str =(String)method.invoke(clazz.getInterfaces(), "admin", "admin123");

        System.out.println(str);

    }


}
